'use strict';
const { Builder, By, until } = require('selenium-webdriver');
const { Before, After, When, Then } = require('@cucumber/cucumber');
const { ContextExclusionPlugin } = require('webpack');
const assert = require("assert");
let driver;

Before(async function () {
    driver = new Builder()
        .forBrowser('chrome')
        .build();

});

After(async function () {
    if (!driver) {
        return;
    }
    // await driver.quit();
});

When('I navigate to the device dashboard', async function () {
    await driver.get('http://localhost/')
    // console.log('first')

});

When('I click the Reboot button of the device at the address {string}', async function (deviceAddress) {
    let address = await driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div/div[2]')).getText()
    if (address == deviceAddress) {
        await driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div/button')).click()
    }

});
Then('the device status indicator becomes green', function () {

    setTimeout(async() => {
        const deviceStatus = driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div/div[3]'))
        assert.equal(await deviceStatus.getAttribute("class"), 'device-info-item-online')
    }, 3000)

});
